package com.balabala.gym_user.controller.admin;

import com.balabala.gym_enum.ResultEnum;
import com.balabala.gym_user.pojo.entity.IntegralRule;
import com.balabala.gym_user.service.IntegralRuleService;
import com.balabala.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author 何涛
 * @Date: 2023/05/01/ 13:20
 * @description 积分规则控制器
 */
@RestController
@CrossOrigin
@RequestMapping("/admin/integralRule")
@Slf4j
@Api(tags = "积分规则后台接口")
public class IntegralRuleController {
    @Autowired
    IntegralRuleService integralRuleService;

    @GetMapping("/{id}")
    @ApiOperation("根据id查找积分规则信息")
    public Result findById(@PathVariable Long id)
    {
        return Result.ok(ResultEnum.GENERALLY_SUCCESS,integralRuleService.getById(id));
    }

    @PostMapping("/add")
    @ApiOperation("添加一条积分规则信息")
    public Result add(@RequestBody IntegralRule integralRule)
    {
        log.info("添加一条积分规则：{}",integralRule.toString());
        integralRuleService.save(integralRule);
        return Result.ok(ResultEnum.GENERALLY_SUCCESS);
    }

    @PutMapping("update")
    @ApiOperation("更新积分规则信息")
    public Result update(@RequestBody IntegralRule integralRule)
    {
        log.info("修改积分规则:{}",integralRule);
        integralRuleService.updateById(integralRule);
        return Result.ok(ResultEnum.GENERALLY_SUCCESS);
    }

    @DeleteMapping("deleteById")
    @ApiOperation("根据id删除积分规则信息")
    public Result deleteById(@RequestParam Long id)
    {
        log.info("删除积分规则：{}",id);
        integralRuleService.removeById(id);
        return Result.ok(ResultEnum.GENERALLY_SUCCESS);
    }


}
